package edu.nf.api.controller.item;

import edu.nf.api.controller.BaseController;
import edu.nf.waimai.dao.item.ItemDAO;
import edu.nf.waimai.dao.item.ItemTypeDAO;
import edu.nf.waimai.dao.item.impl.ItemDAOImpl;
import edu.nf.waimai.dao.item.impl.ItemTypeDAOImpl;
import edu.nf.waimai.model.ltem.Item;
import edu.nf.waimai.model.ltem.ItemType;

import edu.nf.waimai.service.item.impl.ItemTypeServiceImpl;
import org.nf.web.annotation.Model;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

public class ItemTypeController extends BaseController {
    //ItemTypeService service = new ItemTypeServiceImpl();
    ItemTypeDAO dao = new ItemTypeDAOImpl();
    /**
     * 添加商品类型
     * @param itemType
     * @return
     */
    @RequestMapping("/item/itemType/add")
    public View addItemType(@Model ItemType itemType){
        return new JsonView(success(dao.addItemType(itemType)));
    }

    /**
     * 删除商品类型
     * @param itemTypeId
     * @return
     */
    @RequestMapping("/item/itemType/del")
    public View delItemType(@RequestParam("itemTypeId") int itemTypeId){
        return new JsonView(success(dao.delItemTypeById(itemTypeId)));
    }

    /**
     * 通过商家id查询全部的商品类型
     * @param shopId
     * @return
     */
    @RequestMapping("/item/itemType/getItemTypeListByShopId")
    public View getItemTypeListByShopId(@RequestParam("shopId") int shopId){
        return new JsonView(success(dao.listItemTypesByShopId(shopId)));
    }
}
